package com.xmut.controller;

import com.xmut.pojo.ManagerSet;
import com.xmut.pojo.OldMan;
import com.xmut.pojo.Result;
import com.xmut.pojo.Score;
import com.xmut.service.OldManService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;

@Slf4j
@RestController
@CrossOrigin("*")
public class OldManController {

    @Autowired
    private OldManService oldManService;

    //获得所有老人信息
    @GetMapping("/oldMan")
    public Result oldManList()
    {
        List<OldMan> oldManList = oldManService.getList();
        return Result.success(oldManList);
    }
    //根据id来获得老人信息
    @GetMapping("/GetById/{id}")
    public Result GetById(@PathVariable Integer id)
    {
        OldMan oldManList = oldManService.getById(id);
        return Result.success(oldManList);
    }
    @GetMapping("/GetByManagerId/{id}")
    public Result oldManListByManagerId(@PathVariable Integer id)
    {
        List<OldMan> oldManList = oldManService.getByManagerId(id);
        return Result.success(oldManList);
    }

    @GetMapping("/getSet/{id}")
    public Result getSet(@PathVariable Integer id)
    {
        ManagerSet managerSet = oldManService.getSet(id);
        return Result.success(managerSet);
    }
    @PutMapping("/setManaSet/{id}")
    public Result setManaSet(@PathVariable  Integer id, @RequestBody  ManagerSet managerSet)
    {

        oldManService.setManaSet(id,managerSet);
        return Result.success();
    }


    //删除某个老人信息
    @DeleteMapping("/oldMan/{id}")
    public Result oldManDelete(@PathVariable Integer id)
    {

        oldManService.oldManDel(id);
        return Result.success();
    }

    //添加新的老人
    @PostMapping("/oldMan")
    public Result oldManInsert(@RequestBody OldMan oldMan)
    {

        oldManService.oldManIns(oldMan);
        return Result.success();
    }

    @PutMapping("/oldMan/{id}")
    public Result oldManUpdate(@PathVariable  Integer id, @RequestBody  OldMan oldMan)
    {
        oldManService.oldManUpd(id,oldMan);
        return Result.success();
    }
    @PutMapping("/setEvaluate/{id}")
    public Result setEvaluate(@PathVariable  Integer id, @RequestBody Score score)
    {
        System.out.println(score.getRealScore());
        oldManService.setEvaluate(id,score.getRealScore());

        return Result.success();
    }


}
